package com.jy.adscm.operation.hr.controller;


import com.jy.adscm.bean.system.JyMenu;
import com.jy.adscm.exception.AdscmSystemException;
import com.jy.adscm.operation.hr.bean.HrStationManage;
import com.jy.adscm.operation.hr.service.HrStationManageService;
import com.jy.adscm.security.utils.Token;
import com.jy.adscm.support.SimpleCoreResponse;
import com.jy.adscm.utils.AdscmBaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 人力资源-岗位管理 前端控制器
 * </p>
 *
 * @author zyl
 * @since 2020-01-07
 */
@RestController
@RequestMapping("/adscm/operation//hrStationManage")
public class HrStationManageController {
    @Autowired
    RedisTemplate<Object, Token> tokenRedisTemplate;
    @Autowired
    HrStationManageService hrStationManageService;
    @RequestMapping("insert")
    public SimpleCoreResponse insert(@RequestBody HrStationManage hrStationManage, HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        hrStationManage.setCreator(token.getUser().getId().toString());
        hrStationManage.setCreateTime(new Date());
        boolean insert = hrStationManageService.insertHrStationManage(hrStationManage);
        return new SimpleCoreResponse("200","新增成功",insert);
    }
    @RequestMapping("selectStationDescById/{id}")
    public SimpleCoreResponse selectStationDesc(@PathVariable Integer id , HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        HrStationManage hrStationManage = hrStationManageService.selectStationDescById(id);
        return new SimpleCoreResponse("200","查询成功",hrStationManage);
    }
    @RequestMapping("updateStationDesc")
    public SimpleCoreResponse updateStationDesc(@RequestBody HrStationManage hrStationManage , HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        hrStationManage.setStationDescCreator(token.getUser().getId().toString());
        Boolean  result = hrStationManageService.updateStationDesc(hrStationManage);
        return new SimpleCoreResponse("200","查询成功",result);
    }
    @RequestMapping("selectRecruitmentDescById/{id}")
    public SimpleCoreResponse selectRecruitmentDescById(@PathVariable Integer id , HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        HrStationManage hrStationManage = hrStationManageService.selectRecruitmentDescById(id);
        return new SimpleCoreResponse("200","查询成功",hrStationManage);
    }
    @RequestMapping("updateRecruitmentDesc")
    public SimpleCoreResponse updateRecruitmentDesc(@RequestBody HrStationManage hrStationManage , HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        hrStationManage.setRecruitmentDescCreator(token.getUser().getId().toString());
        Boolean result = hrStationManageService.updateRecruitmentDesc(hrStationManage);
        return new SimpleCoreResponse("200","查询成功",result);
    }

    @RequestMapping("/selectMenu")
    public SimpleCoreResponse selectMenu( HttpServletRequest request) throws AdscmSystemException {
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        List<JyMenu> jyMenus=  hrStationManageService.selectMenu();
        return new SimpleCoreResponse("200","查询成功",jyMenus);
    }
    @RequestMapping("/addMenu")
    public SimpleCoreResponse addMenu(@RequestBody JyMenu jyMenu, HttpServletRequest request) throws AdscmSystemException{
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Boolean result =  hrStationManageService.addMenu(jyMenu);
        return new SimpleCoreResponse("200","添加成功",result);
    }
    @RequestMapping("/deleteMenu/{id}")
    public SimpleCoreResponse deleteMenu(@PathVariable Integer id, HttpServletRequest request) throws AdscmSystemException{
        String tokenId = request.getParameter("tokenId");
        Token token = AdscmBaseUtils.getInstance().getTokenByTokenId(tokenId, tokenRedisTemplate);
        Boolean result =  hrStationManageService.deleteMenu(id);
        return new SimpleCoreResponse("200","删除成功",result);
    }

}

